package com.zhumo.sz.gaode;

import com.alibaba.fastjson.JSONObject;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Objects;

/**
 * @author zhumo
 * @comment poi实体
 */

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Poi {

    private String id;
    private String name;
    private String direction;
    private Double distance; //直线距离
    private Double poiWeight;
    private String type;
    private Double lng;
    private Double lat;

    public static Poi init(JSONObject poiJsonObj) {
        if (Objects.isNull(poiJsonObj) || poiJsonObj.size() == 0) {
            throw new IllegalArgumentException("参数异常");
        }else {
            return new Poi(
                    poiJsonObj.getString("id"),
                    poiJsonObj.getString("name"),
                    poiJsonObj.getString("direction"),
                    Double.valueOf(poiJsonObj.getString("distance")),
                    Double.valueOf(poiJsonObj.getString("poiweight")),
                    poiJsonObj.getString("type"),
                    Double.valueOf(poiJsonObj.getString("location").split(",")[0]),
                    Double.valueOf(poiJsonObj.getString("location").split(",")[1])
            );
        }
    }
}

